<?php
if(!defined('_SetYour_')) die('Error');# Definicion de seguridad
// CONSULTA
if($_GET['categoria']) $Cat = (int)$_GET['categoria'];

$Sitos=$SQL->consulta("SELECT set_poster_sitos.*,set_poster_categorias.nombre as label FROM set_poster_categorias RIGHT JOIN set_poster_sitos ON set_poster_sitos.categoria= set_poster_categorias.id ".(($Cat)?"WHERE set_poster_sitos.categoria = $Cat":""));


$Categorias = $SQL->consulta("SELECT id,nombre FROM set_poster_categorias");

foreach($Sitos as $sitio){
	   $sitelist.="<tr style='background:#EEE'>
		<th class='center'>
		<label>$sitio->nombre</label>
		</th>
    <th class='center' onmousemove=\"document.getElementById('poster_".$sitio->id."').style.display='block';\" onmouseout=\"document.getElementById('poster_".$sitio->id."').style.display='none';\">
	<label>$sitio->host</label>
	<div id='poster_".$sitio->id."' class='pag_opt'><a href='?modulo=usuarios&accion=editar&id=".$sitio->id."' class='link-blue'>Ver o Editar</a> | <a href='' class='link-red' onclick=\"if(confirm('De verdad desdea borrar a este usuario?')) document.location.replace('?modulo=poster&accion=eliminar&id=".$sitio->id."'); return false;\">Borrar</a></div>
	</th>
<td class='center'><label>$sitio->label</label></td> 
<td class='center'><input  type=\"checkbox\" name=\"$sitio->id\" /></td> 
	 
  </tr>";
}
?>
<script>
var sitios_checked=false;
function selectall(a){
	var obj = document.poster_sitios;
	if(!sitios_checked){		
		for (i=0;i<obj.length;i++) if(obj[i].type=='checkbox') obj[i].checked=true;
		sitios_checked=true;
	}else{
		for (i=0;i<obj.length;i++) if(obj[i].type=='checkbox') obj[i].checked=false;
		sitios_checked=false;	
	}
}
function GoToCat(i){
	document.location.replace("admin-wmb.php?modulo=poster&categoria="+i);
	
}
</script>
<label class='titulo'><?=$_P['admin_poster']?><br /></label>
<div id="status"></div>
<div  class="marco_est" style="margin-left:140px;">
<a href="admin-wmb.php?modulo=poster&accion=agregar" class="link-n">[ <?=$_P['add']." ".$_P['site']?> ]</a><br />
<a href="admin-wmb.php?modulo=poster&accion=agregar_categoria" class="link-n">[ <?=$_P['add']." ".$_P['category']?> ]</a> 
<select name="poster_categoria" onchange="GoToCat(this.value);">
<option value='0' selected="selected"><?=$_P['all']?></option>
<?php
if(!empty($Categorias)){
	$i=0;
	foreach($Categorias as $categoria){
		$i++;
		echo "<option value='".$categoria->id."' ".(($Cat==$categoria->id)?"selected=\"selected\"":"").">".$categoria->nombre."</option>";
	//	if($rango->id==$Usuario->cargo) $rangoa=$i; REVISAR PARA MEJORAS LOGICAS
	}
}
?>
</select>
<a href="admin-wmb.php?modulo=poster&accion=eliminar_categoria"  onclick="alert(<?=$Cat?>);" class="link-n">[ <?=$_P['delete']." ".$_P['category']?> ]</a> 
<p />
<form name="poster_sitios" action="">
<table width="441" border="0" cellpadding="0" cellspacing="0" class="tabla">
<tr class="headers">
    <th  height="28" width="73"><?=$_P['name']?></th>
    <th><?=$_P['host']?></th>
    <th><?=$_P['category']?></th>
    <th width="18"><a href="" class="link-blue" onclick="selectall(); return false;">*</a></th>
</tr>
<?=$sitelist;?>
<tr class="headers">
    <th  height="28" width="73"><?=$_P['name']?></th>
    <th><?=$_P['host']?></th>
    <th><?=$_P['category']?></th>
    <th width="18"><a href="" class="link-blue" onclick="selectall(); return false;">*</a></th>
</tr>
</table>
</form>
</div>